package com.cjm.one.controller.customer;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjm.one.common.result.Result;
import com.cjm.one.model.base.TokenVo;
import com.cjm.one.model.custom.entity.CustomGrade;
import com.cjm.one.model.custom.entity.CustomerInfo;
import com.cjm.one.model.custom.vo.CustomerInfoVo;
import com.cjm.one.model.custom.vo.RegisterVO;
import com.cjm.one.model.system.vo.LoginVo;
import com.cjm.one.service.AuthLoginService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;

import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/customer")
@Slf4j
public class AuthLoginController {

    @Resource
    private AuthLoginService authLoginService;

    @GetMapping("/emailCode")
    @Operation(summary = "发送邮箱验证码")
    public Result<String> emailCode(@RequestParam("email") String email )  {

        return authLoginService.sendEmailCode(email);
    }
    @PostMapping("/login")
    @Operation(summary = "客户登录")
    public Result<TokenVo> login(@RequestBody LoginVo loginVo){
            return authLoginService.login(loginVo);
    }
    @GetMapping("/getUserInfo")
    @Operation(summary = "获取用户信息")
    public Result<CustomerInfoVo> userInfo(){
        return authLoginService.getUserInfo();

    }
    @PostMapping("/register")
    @Operation(summary = "客户注册")
    public Result<Boolean> register(@Validated @RequestBody RegisterVO registerVO)  {
        return authLoginService.register(registerVO);
    }
    @GetMapping("/checkEmail")
    @Operation(summary = "检查邮箱是否被注册")
    public Result<Boolean> checkEmail(@RequestParam String email){
        return authLoginService.checkEmail(email);
    }

    @GetMapping("/checkEmail/Code")
    @Operation(summary = "检查邮箱验证码")
    public Result<Boolean> checkEmailCode(@RequestParam("email") String email,@RequestParam("code") String code){

        return authLoginService.checkEmailCode(email,code);
    }
}
